#pragma once
#include "stdafx.h"
#include "StrBlob.h"


StrBlob::StrBlob() :data(make_shared<vector<string>>()) 
{
}

StrBlob::StrBlob(initializer_list<string> il) :
	data(make_shared<vector<string>>(il))
{
}

void StrBlob::check(size_type i, const string &msg) const
{
	if (i >= data->size()) {
		throw out_of_range(msg);
	}
}

string& StrBlob::front()
{
	check(0, "front on empty StrBlob");
	return data->front();
}

string& StrBlob::back()
{
	check(0, "back on empty StrBlob");
	return data->back();
}

void StrBlob::pop_back()
{
	check(0, "pop_back on empty StrBlob");
	data->pop_back();
}

const string& StrBlob::front() const
{
	check(0, "front on empty StrBlob");
	return data->front();
}
const string& StrBlob::back() const 
{
	check(0, "back on empty StrBlob");
	return data->back();
}

StrBlobPtr StrBlob::begin() {
	return StrBlobPtr(*this); 
}

StrBlobPtr StrBlob::end() { 
	return StrBlobPtr(*this, data->size()); 
}


ConstStrBlobPtr StrBlob::beginc() const
{
	return ConstStrBlobPtr(*this);
}
ConstStrBlobPtr StrBlob::endc() const
{
	return ConstStrBlobPtr(*this, data->size());
}


void StrBlob_test()
{
	ifstream ifs("../data/book.txt");
	StrBlob blob1;
	for (string str; getline(ifs, str);) {
		blob1.push_back(str);
	}
	const StrBlob blob = blob1;
	for (ConstStrBlobPtr pbeg(blob.beginc()), pend(blob.endc()); pbeg != pend; pbeg.incr()) {
		cout << pbeg.deref() << endl;
	}
}
